package com.c.ctgproject.adapter.guang

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.base.BaseRecyclerViewAdapter
import com.c.ctgproject.entity.guang.DestroyPhotoListEntity
import com.c.ctgproject.retrofit.Constants
import com.c.ctgproject.ui.collect.CheckPhotoActivity
import com.c.ctgproject.ui.collect.DestroyCarUploadImageActivity
import com.c.ctgproject.utils.MyConstants
import com.c.ctgproject.utils.handlerNull
import com.c.ctgproject.utils.noDataHandler
import org.jetbrains.anko.backgroundResource
import org.jetbrains.anko.startActivity

class DestroyTypeAdapter(private val context: Context, private val mList: ArrayList<DestroyPhotoListEntity.DataBean.ListBean>) : BaseRecyclerViewAdapter(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_destroy_type_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
//            when (data.destructivePhoto) {
//                0 -> {
////                    未完成
//                    holder.mLine.visibility = View.VISIBLE
//                    holder.mFinishRL.visibility = View.VISIBLE
//                }
//                1 -> {
//                    //已完成
//                    holder.mLine.visibility = View.GONE
//                    holder.mFinishRL.visibility = View.GONE
//
//                }
//                else->{
//                    holder.mLine.visibility = View.VISIBLE
//                    holder.mFinishRL.visibility = View.VISIBLE
//                }
//            }
            //拍照
            if (data.destructivePhoto == 0) {
                holder.mFinishBTN.text = "上传车辆照片"
                holder.mFinishBTN.backgroundResource = R.drawable.bg_btn_green_radius
            } else {
                holder.mFinishBTN.text = "查看车辆照片"
                holder.mFinishBTN.backgroundResource = R.drawable.bg_btn_red_radius
            }



            holder.mCodeTV.text = data.carCode.noDataHandler()
            holder.vin.text = data.carVin.noDataHandler()
            holder.carPlate.text = data.carPlate.noDataHandler()
            holder.mTimeTV.text = data.realFinishTime.noDataHandler()
            holder.mFinishRL.setOnClickListener {
                holder.mFinishBTN.performClick()
            }
            holder.mFinishBTN.setOnClickListener {
                if (data.destructivePhoto == 0) {
                    //去传照片
                    val intent = Intent(context, DestroyCarUploadImageActivity::class.java)
                    intent.putExtra(MyConstants.CAR_ID, data.carId)
                    intent.putExtra(MyConstants.POSITION,position)
                    context.startActivity(intent)
                } else {
                    context.startActivity<CheckPhotoActivity>(MyConstants.ID to data.carId)
                }
            }
            holder.mParentLL.setOnClickListener {
                context.startActivity<CheckPhotoActivity>(MyConstants.ID to data.carId)
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val vin: TextView = view.findViewById(R.id.vin)
        val carPlate: TextView = view.findViewById(R.id.carPlate)
        val mCodeTV: TextView = view.findViewById(R.id.mCodeTV)
        val mTimeTV: TextView = view.findViewById(R.id.mTimeTV)
        val mFinishBTN: Button = view.findViewById(R.id.mFinishBTN)
        val mFinishRL: RelativeLayout = view.findViewById(R.id.mFinishRL)
        val mLine: View = view.findViewById(R.id.mLine)
        val mParentLL:LinearLayout=view.findViewById(R.id.mParentLL)
    }
}